package com.example.newproject_overseas.Screen


import androidx.compose.foundation.Canvas
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.example.newproject_overseas.R
import com.example.newproject_overseas.components.TopApp

@Composable
fun Rollover(navController: NavHostController) {

    Box(  modifier = Modifier
        .fillMaxSize()
        .background(color = Color(0XFFEFF0F3))){

        Column(
            modifier = Modifier
                .fillMaxSize()
                .background(color = Color(0XFFEFF0F3)),

            ) {
            TopApp(title = "Rollover", navController = navController)
            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(45.dp)
                    .background(Color(0xFFFFF6D4)),
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Text(
                    text = "Your repayment period will be extended after you repay.",
                    color = Color(0xFF5F5F5F)
                )
            }

            Column(
                modifier = Modifier

                    .padding(top = 20.dp)
                    .fillMaxWidth()
                    .clip(RoundedCornerShape(20.dp))
                    .padding(horizontal = 10.dp)
                    .height(200.dp)
                    .background(Color(0xFFFFFFFF))
            ) {
                Column(
                    modifier = Modifier

                        .padding(horizontal = 10.dp)
                        .padding(vertical = 15.dp)


                ) {
                    Row() {
                        VerticalLine()
                        Text(
                            text = "Pay niw",
                            fontSize = 25.5.sp,
                            fontWeight = FontWeight.Normal
                        )

                        Spacer(modifier = Modifier.weight(1f))

                        Text(
                            text = "₹",
                            fontSize = 30.sp,
                            fontWeight = FontWeight.Bold,
                            color = Color(0xFFFFCC00)
                        )
                        Text(
                            text = "200,000",
                            fontSize = 30.sp,
                            fontWeight = FontWeight.Bold,
                            color = Color(0xFFFFCC00)
                        )
                    }

                    Column(modifier = Modifier.padding(top = 12.dp)) {
                        HorizontalLine(

                            lineColor = Color(0xFFD8D8D8),
                            lineWidth = 1.dp
                        )
                    }

                    Row(modifier = Modifier.padding(top = 12.dp)) {
                        Text(text = "Delayed date:", fontSize = 18.sp, color = Color(0xFF999999))
                        Spacer(modifier = Modifier.weight(1f))
                        Text(text = "2023-02-21 02:30:00", fontSize = 18.sp)
                    }

                    Row(modifier = Modifier.padding(top = 12.dp)) {
                        Text(text = "Extend time:", fontSize = 18.sp, color = Color(0xFF999999))
                        Spacer(modifier = Modifier.weight(1f))
                        Text(text = "7 DAY", fontSize = 18.sp)
                    }

                    Row(modifier = Modifier.padding(top = 12.dp)) {
                        Text(
                            text = "Recording(max.10000):",
                            fontSize = 18.sp,
                            color = Color(0xFF999999)
                        )
                        Spacer(modifier = Modifier.weight(1f))
                        Text(text = "0 Time", fontSize = 18.sp)
                    }
                }


            }


            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(45.dp),
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Text(
                    text = "This loan is provided by a third-party company Loan House",
                    color = Color(0xFF999999)
                )
            }




        }


        //底部按钮
        Button(onClick = { /*TODO*/ }, modifier = Modifier
            .fillMaxWidth(1f)
            .height(44.dp)
            .align(Alignment.BottomCenter),
            colors = ButtonDefaults.buttonColors(Color(0xFFFFCC00)),
            shape = RoundedCornerShape(4.5.dp)) {
            androidx.compose.material.Text(
                modifier = Modifier,
                text = "Need to repay loan 5250",
                color = Color(0xFFFFFFFF),
                fontSize = 20.sp
            )
        }

    }

}


@Composable
fun VerticalLine() {
    Canvas(
        modifier = Modifier
            .width(4.dp)
            .height(30.dp)
            .padding(top = 8.dp)
    ) {
        drawRoundRect(
            color = Color(0xFFFFCC00),
            cornerRadius = CornerRadius.Zero,
            size = size
        )
    }
}

@Composable
fun HorizontalLine(lineColor: Color = Color.Black, lineWidth: Dp = 1.dp) {
    Canvas(
        modifier = Modifier
            .fillMaxWidth()
            .height(1.dp)
    ) {
        drawLine(
            color = lineColor,
            start = Offset(0f, 0f),
            end = Offset(size.width, 0f),
            strokeWidth = lineWidth.toPx(),
            cap = StrokeCap.Butt
        )
    }
}

@Preview
@Composable
fun RolloverPreview() {
    val navController = rememberNavController() // 假设这里使用了导航控制器
    Rollover(navController)
}

